<?php
/**
 *
 * (model)
 */
namespace App\Models\SalesReport;

use App\Models\Product\ProductClassify;
use Illuminate\Database\Eloquent\Model;
class PaymentCNDetail extends Model
{
    protected $table = 'sr_payment_none_classify';

    protected $guarded = [];

    public $timestamps = false;

    public function classify(){
        return $this->belongsTo(ProductClassify::class,'classify_id');
    }

    public static $_basic = [
        'report_date' => ['title' => '日期','sumField' => false,'per' => false],
        'season' => ['title' => '季节性','sumField' => false,'per' => false],
        'classify' => ['title' => '品类','sumField' => false,'per' => false],
    ];

    public static function getDataBasic($row): array
    {
        return [
            $row->report_date,
            ProductClassify::$_season[$row->classify->season ?? 3],
            $row->classify->title ?? '',
        ];
    }

    public static function headersField(): array
    {
        return self::$_basic + PaymentTNSummary::$_common;
    }

    public static function getDownloadData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getNumDataCommon($row);
            yield self::getDataBasic($row) + PaymentTNSummary::getPerDataCommon($row);
        }
    }

    public static function getDownloadNumData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getNumDataCommon($row);
        }
    }

    public static function getDownloadPerData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getPerDataCommon($row);
        }
    }
}
